use std::env;
use std::process;

const USAGE: &str = "usage: fibonacci <n>";

fn main() {
    let args: Vec<String> = env::args().collect();
    if args.len() != 2 {
        println!("{}", USAGE);
        process::exit(1);
    }

    let n: u32 = match args[1].trim().parse() {
        Ok(num) => num,
        Err(_) => {
            println!("{}", USAGE);
            process::exit(1);
        }
    };
    if n <= 0 {
        println!("{}", USAGE);
        process::exit(1);
    }

    let mut f1 = 1;
    let mut f2 = 1;
    for i in 1..n+1 {
        if i == 1 || i == 2 {
            print!("{} ", 1)
        } else {
            let tmp = f2;
            f2 = tmp + f1;
            f1 = tmp;
            print!("{} ", f2)
        }
    }
}
